﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace KSOAPlus
{
    public partial class SysConfig : Form
    {
        public SysConfig()
        {
            InitializeComponent();
        }

        Common Init = new Common();

        private void SysConfig_Load(object sender, EventArgs e)
        {
            rightcopy.Text = Common.rightcopy;
            string mssqlConnectionString = ConfigurationManager.ConnectionStrings["mssqlConnectionString"].ToString();

            string EnterpriseName = ConfigurationManager.AppSettings["EnterpriseName"].ToString();
            string RkmxSqlStr = ConfigurationManager.AppSettings["RkmxSqlStr"].ToString();
            string CkmxSqlStr = ConfigurationManager.AppSettings["CkmxSqlStr"].ToString();
            string KcmxSqlStr = ConfigurationManager.AppSettings["KcmxSqlStr"].ToString();
            string ServerURL = ConfigurationManager.AppSettings["ServerURL"].ToString();

            txtConnectionString.Text = mssqlConnectionString;
            txtEnterpriseName.Text = EnterpriseName;
            txtUrlAddress.Text = ServerURL;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try 
            {
                Init.UpdateConnectionStringsConfig("mssqlConnectionString", txtConnectionString.Text, "数据库地址");
                Init.UpdateappSettingsConfig("EnterpriseName", txtEnterpriseName.Text);
                Init.UpdateappSettingsConfig("ServerURL", txtUrlAddress.Text);
                MessageBox.Show("保存成功！\r\n重启后生效！");
                this.Dispose();
                this.Close();
                Environment.Exit(0); 
            }
            catch (Exception ex)
            {
                Init.WriteLog(ex.ToString(), true);            
            }
        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnPlugIn_Click(object sender, EventArgs e)
        {
            string fullfile = "CmCaptureOcx_2.3.9_20180125.exe";
            if (Init.fileExist(@fullfile))
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.FileName = @fullfile;
                process.Start();
            }
            else
            {
                MessageBox.Show("控件文件不存在！");
            }
        }  
    }
}
